package com.xu.mb3.mbtools;

import com.xu.mybatis.entity.UserAmountInfo;
import com.xu.mybatis.entity.UserInfo;
import org.apache.ibatis.ognl.Ognl;
import org.apache.ibatis.ognl.OgnlException;

import java.util.Arrays;
import java.util.List;

/**
 * 解析ognl表达式
 *
 * @author xuguan
 * @since 2024/11/13
 */
public class OgnlSample {

    public static void ognlSample() {
        try {
            final UserInfo userInfo = new UserInfo(1L, "xuguan", "123456789", "18", 1, "Java", "China", null, null, 0);
            final Object name = Ognl.getValue("name", userInfo);
            final Object getName = Ognl.getValue("getName()", userInfo);
            System.out.println(name);
            System.out.println(getName);

            final List<Integer> list = Arrays.asList(1, 2, 3);
            final Object i = Ognl.getValue("[0]", list);
            final Object size = Ognl.getValue("size()", list);
            System.out.println(i);
            System.out.println(size);
        } catch (OgnlException e) {
            throw new RuntimeException(e);
        }
    }

    public static void main(String[] args) {
        ognlSample();
    }
}
